import {Index} from './index-model.js';
var app = getApp();
var index = new Index();
Page({
  data: {
    imgsbox: [],
    swiperCurrent: 0,
    autoplay: true,
    interval: 3000,
    duration: 800,
    // circular: true,
    // // 将轮播图组件自带的小点隐藏
    indicatorDots: false,
     dataList:[1,2,3,4,5,6],
  },
  
  onLoad() {
    var that=this;
    my.canIUse('favorite');
    if(app.globalData.goodsid>0)
    {
      my.navigateTo({
       url: '/pages/goodsDetail/goodsDetail?id='+app.globalData.goodsid
    })
    }
    that._loadData();
  },
  _loadData:function()
  {
    var that = this;
      //获取首页分类
      index.getCategory((data)=>{
        that.setData({
          categoryArr:data.data
        })
      })

      //获取首页banner图
      index.getBanner((data)=>{
        that.setData({  
          bannerArr:data.data
        })
      })

      //获取首页有限商品根据分类ID
      index.getLimitProduct((data)=>{
        var products = data.data;
        for(let i=0;i<products.length;i++)
        {
          for(let k=0;k<products[i].productArr.length;k++)
          {
             products[i].productArr[k].goods_price = parseInt(products[i].productArr[k].goods_price/31)
          } 
        }
        this.setData({
          productArr:data.data
        })
      })
  },
  goodsname(e){
   var that = this;
   var name=e.detail.value;
   that.setData({
      name:name
   })
  },
  sosuo(){
    var that = this;
    var name = that.data.name;
    if(!name)
    {
      my.alert({
        title: '搜索提示',
        content:'请输入关键词' 
      });
      return;
    }
       my.navigateTo({
       url: '/pages/goodslist/goodslist?name='+name+'&type='+1 //type=1表示搜索进去的
  })

  }
});
